//
//  AppDelegate.swift
//  Swift-weibo
//
//  Created by 朱万龙 on 2016/12/9.
//  Copyright © 2016年 zwl. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

//        sleep(2)
        window = UIWindow()
        
        window?.backgroundColor = UIColor.white
        
        window?.rootViewController = ZLMainViewController()
        
        window?.makeKeyAndVisible()
        
        loadAppInfo()
        
        return true
    }
}
extension AppDelegate{
    
    fileprivate func loadAppInfo(){
        ///模拟网络加载数据JSON
        DispatchQueue.global().async {
            //1、url
            let url = Bundle.main.url(forResource: "Main.json", withExtension: nil)
            //2、data
            let data = NSData(contentsOf: url!)
            //3、写入磁盘
            //1>磁盘路径
            let pathfile = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            let jsonPath = (pathfile as NSString).appendingPathComponent("Main.json")
            data?.write(toFile: jsonPath, atomically: true)
            
            print(pathfile)
            
            
        }
        
    print("加载网络JSON")
    }
    
}

